<template>
  <div class="recommend">
    <div class="lunbo">
      <van-swipe
        class="my-swipe"
        :autoplay="3000"
        indicator-color="white"
        :height="80"
      >
        <van-swipe-item v-for="(item, index) in lunbo" :key="index"
          ><img class="auto-img" :src="item.i" alt=""
        /></van-swipe-item>
      </van-swipe>
    </div>

    <div class="lizi0">
      <!-- 这里使用v-for遍历 -->
      <div class="yonghu" v-for="(item, index) in tuijian" :key="item.id">
        <div class="yonghu_top">
          <div class="touxiang">
            <img class="auto-img" :src="item.a.p" alt="" />
          </div>
          <div class="yhm_right">
            <span>{{ item.a.n }}</span> <i>Lv.{{ item.a.lvl }}</i>
          </div>
        </div>
        <div class="yonghu_center" @click="btn(item.id)">
          <img class="auto-img" :src="item.img" alt="" />
        </div>
        <div class="yonghu_bottom">
          <div class="bottom" v-if="item.collect_status == 0">
            <div class="bottom-sc">
              <span>{{ item.collect_count_text }}</span>
            </div>
            <div class="bottom-ico" @click="btncollect(index)">
              <van-icon name="star-o" size="0.5rem" />
            </div>
          </div>
          <div class="bottom" v-if="item.collect_status == 1">
            <div class="bottom-sc"><span>1.5万人点赞</span></div>
            <div class="bottom-ico">
              <van-icon name="like-o" size="0.5rem" />
            </div>
          </div>
          <div class="title">{{ item.trim_title }}</div>
        </div>
      </div>
      <div class="btn" @click="btnadd">点击加载更多</div>
      <!-- ============== -->
    </div>
  </div>
</template>

<script>
export default {
  name: "Recommend",
  data() {
    return {
      keydata: 0,
      lunbo: [],
      arr:[],
      tuijian: [],
      index: 1,
    };
  },

  created() {
    this.getProductType();
  },

  methods: {
    // 点击收藏
    btncollect(index) {

      // 本地储存;
      this.arr.push(this.tuijian[index].id);
      localStorage.setItem("collectlist", JSON.stringify(this.arr));
    },
    btn(id) {
      this.$router.push({ name: "menu", params: { id } });
    },

    getProductType() {
      this.axios({
        method: "get",
        url: "/home/recommended/0/10",
      })
        .then((result) => {
          // console.log("Recommend",result);
          // lunbo数据
          this.lunbo = result.data.result.banner;

          let res = result.data.result.list;
          // console.log(res);
          res.forEach((ele) => {
            if (ele.type === 1) {
              this.tuijian.push(ele.r);
            }
          });
          //   console.log(this.tuijian);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    btnadd() {
      this.index++;
      let num = this.index * 10;
      // console.log(num);
      this.axios({
        method: "get",
        url: `/home/recommended/${num}/10`,
      })
        .then((result) => {
          // lunbo数据
          this.lunbo = result.data.result.banner;

          let res = result.data.result.list;
          //   console.log(res);
          res.forEach((ele, index) => {
            if (ele.type === 1) {
              this.tuijian.push(ele.r);
            }
          });
          //   console.log(this.tuijian);
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style lang="less" scoped>
.recommend {
  width: 100%;
  height: 519px;
  overflow: auto;
}
.recommend::-webkit-scrollbar {
  width: 0 !important;
}
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 80px;
  text-align: center;
  //   background-color: #39a9ed;
}
.lizi0 {
  width: 100%;
  height: 100%;
  .yonghu {
    width: 100%;
    min-height: 330px;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    margin-bottom: 10px;
    // background-color: antiquewhite;
    .yonghu_top {
      width: 100%;
      height: 50px;

      //   background-color: #ed39de;
      border-top: 1px solid transparent;
      .touxiang {
        float: left;
        margin-top: 5px;
        margin-left: 10px;
        width: 35px;
        height: 35px;
        // background-color: antiquewhite;
        overflow: hidden;
        border-radius: 50%;
        border: 1px solid #ccc;
      }
      .yhm_right {
        float: left;
        margin-left: 15px;
        margin-top: 18px;
        span {
          font-size: 0.4rem;
          font-weight: bold;
        }
        i {
          color: rgb(214, 153, 19);
          font-size: 0.11rem;
        }
      }
    }
    .yonghu_center {
      width: 100%;
      height: 70%;
      //   background-color: #39edd5;
    }
    .yonghu_bottom {
      margin-top: 15px;
      width: 100%;
      height: 15%;
      .bottom {
        width: 90%;
        height: 20px;
        // background-color: blue;
        display: flex;
        justify-content: space-between;
        padding: 0 5%;
      }
      .title {
        margin-top: 8px;
        margin-left: 15px;
        width: 90%;
        padding: 0 5%;
        height: 30px;
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
      }
    }
  }
}
.btn {
  width: 100%;
  text-align: center;
}
.auto-img {
  width: 100%;
  display: block;
}
</style>